package com.tracker

class ManagerController {
	
	ManagerService managerService
	
		
	def getlist = {		
			println(params)
			if (params.get("node") == "CompanyTreeRoot") {
				println("ManagerController Test Tur")
				def dbid=1
					redirect(controller: "tur", action: "getlist",params:[id:dbid])
			}
			else if(params.get("node") =~ "Tur_") {
				println("ManagerController Test Hotel")
				def dbid=managerService.getNodeId(params.get("node"))
					redirect(controller:"hotel", action:"getlist",params:[id:dbid])				
			}	
			else if (params.get("node") =~ "Hotel") {
				println("ManagerController Test Request")
				def dbid=managerService.getNodeId(params.get("node"))
					redirect(controller:"times", action:"getlist",params:[id:dbid])
			}
			
			else if (params.get("node") =~ "Times_") {
				println("ManagerController Test Request")
				def dbid=managerService.getNodeId(params.get("node"))
					redirect(controller:"request", action:"getlist",params:[id:dbid])
			}	
	}
		
		def getelement={				
			if (params.get("node")=="CompanyTreeRoot"){
				def dbid=1
				redirect(controller:"company", action: "getelement",params: [id:dbid])				
			}
			else if (params.get("node") =~ "Tur_"){
				def dbid=managerService.getNodeId(params.get("node"))
				redirect(controller:"tur", action:"getelement", params: [id:dbid])	
			}
			else if (params.get("node") =~ "Hotel_") {
				println("ManagerController Test Hotel")
				def dbid=managerService.getNodeId(params.get("node"))
					redirect(controller:"hotel", action:"getelement", params: [id:dbid])
			}		
			else if (params.get("node") =~ "Times_") {
				println("ManagerController Test Times")
				def dbid=managerService.getNodeId(params.get("node"))
					redirect(controller:"times", action:"getelement", params: [id:dbid])			
		}
		 else if (params.get("node") =~ "Request_") {
			 println("ManagerController getelement Request")
			def dbid=managerService.getNodeId(params.get("node"))
			redirect(controller:"request", action:"getelement", params: [id:dbid])				
			}		
	}
		
		
		def deleteElement={			
			if (params.get("node") =~ "Tur_"){
				println("DELETE TUR")
				def dbid=managerService.getNodeId(params.get("node"))
				redirect(controller:"tur", action:"deleteElement", params: [id:dbid])
			}
			if (params.get("node") =~ "Hotel_"){
				println("DELETE Hotel")
				def dbid=managerService.getNodeId(params.get("node"))
				redirect(controller:"hotel", action:"deleteElement", params: [id:dbid])
			}
			if (params.get("node") =~ "Times_"){
				println("DELETE Times")
				def dbid=managerService.getNodeId(params.get("node"))
				redirect(controller:"times", action:"deleteElement", params: [id:dbid])
			}			
			if (params.get("node") =~ "Request_"){
				println("DELETE REQUEST")
				def dbid=managerService.getNodeId(params.get("node"))
				redirect(controller:"request", action:"deleteElement", params: [id:dbid])
			}						
		}
				
		
		def editElement={						
			println("EDIT")
			if(params.get("node")=~"Tur_"){
				println("EDIT TUR")	
				println "Tur-------------------------------->${params}"													
				def dbid=managerService.getNodeId(params.get("node"))	
				params.put('id', dbid)
				redirect(controller:"tur", action:"editElement", params:params)
			}
			 if(params.get("node")=~"Hotel_"){
				println("EDIT Hotel")
				println "Hotel-------------------------------->${params}"
				def dbid=managerService.getNodeId(params.get("node"))
				params.put('id', dbid)
				redirect(controller:"hotel", action:"editElement", params:params)
			}
			 if(params.get("node")=~"Times_"){
				 println("EDIT Times")
				 println "Times-------------------------------->${params}"
				 def dbid=managerService.getNodeId(params.get("node"))
				 params.put('id', dbid)
				 redirect(controller:"times", action:"editElement", params:params)
			 }
			 if(params.get("node")=~"Request_"){
				 println("EDIT Request")
				 println "Request-------------------------------->${params}"
				 def dbid=managerService.getNodeId(params.get("node"))
				 params.put('id', dbid)
				 redirect(controller:"request", action:"editElement", params:params)
			 }
	}
			
		
			
		
		def addElement = {
		println("***************************ADD TUR***************************")
		if (params.get("node")=="CompanyTreeRoot"){		
			def node=1
			params.put('id',node)
			redirect(controller:"tur", action:"addElement", params:params)
		}
		if (params.get("node")=~"Tur_"){
			println("HOTEL = "+params)
			 def node=managerService.getNodeId(params.get("node"))
			params.put('id',node)
			redirect(controller:"hotel", action:"addElement", params:params)
		}
		if (params.get("node")=~"Hotel_"){
			println("Add TIMES")
			println(params)
			def node=managerService.getNodeId(params.get("node"))
			println("node = "+node)
		   params.put('id',node)
		   redirect(controller:"times", action:"addElement", params:params)
	   }
		if (params.get("node")=~"Times_"){
			println("Add Request")
			println(params)
			def node=managerService.getNodeId(params.get("node"))
			println("node = "+node)
		   params.put('id',node)
		   redirect(controller:"request", action:"addElement", params:params)
	   }			
	}	
}
